package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/dish")
@RequiredArgsConstructor
@Api(tags = "菜品管理")
public class DishController {

    private final DishService dishService;

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @ApiOperation("菜品分页查询接口")
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        PageResult pageResult = dishService.page(dishPageQueryDTO);
        return Result.success(pageResult);
    }
    /**
     * 新增菜品
     */
    @PostMapping
    @ApiOperation("新增菜品接口")
    public Result save(@RequestBody DishDTO dishDTO) {
        dishService.save(dishDTO);
        return Result.success();
    }
    /**
     *
     * 单个或者批量删除数据
     */
    @DeleteMapping
    @ApiOperation("删除菜品接口")
    public Result delete(@RequestParam List<Long> ids) {
        dishService.delete(ids);
        return Result.success();
    }

    /**
     * 修改菜品的起售与停售
     */
    @ApiOperation("修改菜品的起售与停售接口")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Long status , Long id) {
        dishService.updateStatus(status , id);
        return Result.success();
    }
    /**
     * 修改菜品的数据回显
     */
    @ApiOperation("修改菜品的数据回显接口")
    @GetMapping("/{id}")
    public Result<DishVO> SelectByDishId(@PathVariable Long id) {
        DishVO dishVO = dishService.SelectByDishId(id);
        return Result.success(dishVO);
    }
    /**
     * 修改菜品
     */
    @ApiOperation("修改菜品")
    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO) {
        dishService.update(dishDTO);
        return Result.success();
    }
    /**
     * 根据分类id查询菜品
     *
     */
    @GetMapping("/list")
    public Result<List<Dish>> list(@RequestParam Long categoryId) {
        List<Dish> dishes = dishService.list(categoryId);
        return Result.success(dishes);
    }

}
